package com.loriot.common.car_pooling_1094;

/**
 * @Title: pointsThatIntersectWithCars_2848
 * @Package: com.loriot.common
 * @Description:
 * @Author: zzy boy
 * @Date: 2025/10/21 10:36
 * @Version: 0.0.1-alpha
 */

public class Main {
    class Solution {
        public boolean carPooling(int[][] trips, int capacity) {
            int start = 1000;
            int end = 0;
            for(int[] item:trips){
                if(start>item[1])start = item[1];
                if(end<item[2])end = item[2];
            }
            int length = end - start + 1;
            int[] difference = new int[length];
            for(int[] item:trips){
                difference[item[1]-start]+=item[0];
                difference[item[2]-start]-=item[0];
            }

            for(int item:difference){
                capacity-=item;
                if(capacity<0)return false;
            }

            return true;

        }
    }
}
